
import 'dart:convert';
import 'dart:io';

var f1 = File("/data/data/com.example.t_mb_03/to_day_file");
var f2 = File("/data/data/com.example.t_mb_03/sj_file");


void save_to_day_file(int day, int read_target){
  f1.writeAsStringSync(json.encode([day, read_target]));
}

List<dynamic> read_to_day_file(){
  if(!f1.existsSync()){
    f1.writeAsStringSync(json.encode([0, 0]));
  }
  return List<dynamic>.from(json.decode(f1.readAsStringSync()));
}

void save_sj_file(String book_id, String title, String cover_image, String author_name, int time_count, int read_jd, int read_jd_all){
  var dic = read_sj_file();
  dic.addAll({title : [book_id, title, cover_image, author_name, time_count, read_jd, read_jd_all]});
  f2.writeAsStringSync(json.encode(dic));
}
Map<String, List<dynamic>> read_sj_file(){
  if(!f2.existsSync()){
    f2.writeAsStringSync(json.encode({}));
  }

  return Map<String, List<dynamic>>.from(json.decode(f2.readAsStringSync()));
}